package org.sgr.money.manager.frame;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.sgr.money.manager.dto.SubjectDto;

public class SubjectMgrModify extends Composite {

	private Label labelParent = null;
	private Text textParent = null;
	private Label labelParentCode = null;
	private Text textParentCode = null;
	private Label labelCode = null;
	private Text textCode = null;
	private Label labelSubName = null;
	private Text textSubName = null;

	private Label labelSubType = null;
	private Combo comboSubType = null;
	private Label labelSubLevel = null;
	private Text textSubLevel = null;
	private Label labelCrDr = null;
	private Combo comboCrDr = null;
	private Label labelNegativeBal = null;
	private Combo comboNegativeBal = null;
	private Button btnOk = null;
	private Button btnCancel = null;
	private Label labelMemo = null;
	private Text textAreaMemo = null;

	public SubjectMgrModify(Composite parent, int style, SubjectDto parentSubjectDto, SubjectDto subjectDto) {
		super(parent, style);
		initialize();
		setParentData(parentSubjectDto);
		loadData(subjectDto);
	}

	private void initialize() {

		labelParentCode = new Label(this, SWT.NONE);
		labelParentCode.setText("父 级 科 目 号");
		FormData formDataLabelParentCode = new FormData();
		formDataLabelParentCode.top = new FormAttachment(0, 20);
		formDataLabelParentCode.left = new FormAttachment(0, 20);
		formDataLabelParentCode.width = 80;
		labelParentCode.setLayoutData(formDataLabelParentCode);

		textParentCode = new Text(this, SWT.BORDER);
		FormData formDataTextParentCode = new FormData();
		formDataTextParentCode.top = new FormAttachment(0, 20);
		formDataTextParentCode.left = new FormAttachment(0, 105);
		formDataTextParentCode.width = 130;
		textParentCode.setLayoutData(formDataTextParentCode);
		Color color = new Color(Display.getCurrent(), 246, 246, 246);
		textParentCode.setBackground(color);
		textParentCode.setEditable(false);

		labelParent = new Label(this, SWT.NONE);
		labelParent.setText("父级科目名称");
		FormData formDataLabelParent = new FormData();
		formDataLabelParent.top = new FormAttachment(0, 20);
		formDataLabelParent.left = new FormAttachment(0, 280);
		formDataLabelParent.width = 80;
		labelParent.setLayoutData(formDataLabelParent);

		textParent = new Text(this, SWT.BORDER);
		textParent.setEditable(false);
		FormData formDataTextParent = new FormData();
		formDataTextParent.top = new FormAttachment(0, 20);
		formDataTextParent.left = new FormAttachment(0, 370);
		formDataTextParent.width = 190;
		textParent.setLayoutData(formDataTextParent);
		textParent.setBackground(color);

		labelCode = new Label(this, SWT.NONE);
		labelCode.setText("科     目     号");
		FormData formDataLabelCode = new FormData();
		formDataLabelCode.top = new FormAttachment(0, 50);
		formDataLabelCode.left = new FormAttachment(0, 20);
		formDataLabelCode.width = 80;
		labelCode.setLayoutData(formDataLabelCode);

		textCode = new Text(this, SWT.BORDER);
		FormData formDataTextCode = new FormData();
		formDataTextCode.top = new FormAttachment(0, 50);
		formDataTextCode.left = new FormAttachment(0, 105);
		formDataTextCode.width = 130;
		textCode.setLayoutData(formDataTextCode);

		labelSubName = new Label(this, SWT.NONE);
		labelSubName.setText("科  目  名  称");
		FormData formDataLabelSubName = new FormData();
		formDataLabelSubName.top = new FormAttachment(0, 50);
		formDataLabelSubName.left = new FormAttachment(0, 280);
		formDataLabelSubName.width = 80;
		labelSubName.setLayoutData(formDataLabelSubName);

		textSubName = new Text(this, SWT.BORDER);
		FormData formDataTextSubName = new FormData();
		formDataTextSubName.top = new FormAttachment(0, 50);
		formDataTextSubName.left = new FormAttachment(0, 370);
		formDataTextSubName.width = 190;
		textSubName.setLayoutData(formDataTextSubName);

		labelSubLevel = new Label(this, SWT.NONE);
		labelSubLevel.setText("科  目  级  别");
		FormData formDataLabelSubLevel = new FormData();
		formDataLabelSubLevel.top = new FormAttachment(0, 80);
		formDataLabelSubLevel.left = new FormAttachment(0, 20);
		formDataLabelSubLevel.width = 80;
		labelSubLevel.setLayoutData(formDataLabelSubLevel);

		textSubLevel = new Text(this, SWT.BORDER);
		FormData formDataTextSubLevel = new FormData();
		formDataTextSubLevel.top = new FormAttachment(0, 80);
		formDataTextSubLevel.left = new FormAttachment(0, 105);
		formDataTextSubLevel.width = 130;
		textSubLevel.setLayoutData(formDataTextSubLevel);
		textSubLevel.setBackground(color);
		textSubLevel.setEditable(false);

		labelSubType = new Label(this, SWT.NONE);
		labelSubType.setText("科  目  类  型");
		FormData formDataTextSubType = new FormData();
		formDataTextSubType.top = new FormAttachment(0, 80);
		formDataTextSubType.left = new FormAttachment(0, 280);
		formDataTextSubType.width = 80;
		labelSubType.setLayoutData(formDataTextSubType);

		createComboSubType();

		labelCrDr = new Label(this, SWT.NONE);
		labelCrDr.setText("余  额  方  向");
		FormData formDataLabelCrDr = new FormData();
		formDataLabelCrDr.top = new FormAttachment(0, 110);
		formDataLabelCrDr.left = new FormAttachment(0, 20);
		formDataLabelCrDr.width = 80;
		labelCrDr.setLayoutData(formDataLabelCrDr);

		createComboCrDr();

		labelNegativeBal = new Label(this, SWT.NONE);
		labelNegativeBal.setText("余额允许为负");
		FormData formDataLabelNegativeBal = new FormData();
		formDataLabelNegativeBal.top = new FormAttachment(0, 110);
		formDataLabelNegativeBal.left = new FormAttachment(0, 280);
		formDataLabelNegativeBal.width = 80;
		labelNegativeBal.setLayoutData(formDataLabelNegativeBal);

		createComboNegativeBal();

		labelMemo = new Label(this, SWT.NONE);
		FormData formDataLabelMemo = new FormData();
		formDataLabelMemo.top = new FormAttachment(0, 140);
		formDataLabelMemo.left = new FormAttachment(0, 20);
		formDataLabelMemo.width = 80;
		labelMemo.setLayoutData(formDataLabelMemo);
		labelMemo.setText("说            明");

		textAreaMemo = new Text(this, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
		FormData formDataTextAreaMemo = new FormData();
		formDataTextAreaMemo.top = new FormAttachment(0, 140);
		formDataTextAreaMemo.left = new FormAttachment(0, 105);
		formDataTextAreaMemo.width = 440;
		formDataTextAreaMemo.height = 60;
		textAreaMemo.setLayoutData(formDataTextAreaMemo);

		this.setLayout(new FormLayout());
		setSize(new Point(590, 270));

		btnOk = new Button(this, SWT.NONE);
		FormData formDataBtnOk = new FormData();
		formDataBtnOk.top = new FormAttachment(0, 220);
		formDataBtnOk.left = new FormAttachment(0, 105);
		formDataBtnOk.width = 120;
		btnOk.setLayoutData(formDataBtnOk);
		btnOk.setText("确  定");

		btnCancel = new Button(this, SWT.NONE);

		FormData formDataBtnCancel = new FormData();
		formDataBtnCancel.top = new FormAttachment(0, 220);
		formDataBtnCancel.left = new FormAttachment(0, 260);
		formDataBtnCancel.width = 120;
		btnCancel.setLayoutData(formDataBtnCancel);
		btnCancel.setText("取  消");
	}

	/**
	 * This method initializes comboSubType
	 * 
	 */
	private void createComboSubType() {
		comboSubType = new Combo(this, SWT.NONE);
		FormData formDataCmbSubType = new FormData();
		formDataCmbSubType.top = new FormAttachment(0, 80);
		formDataCmbSubType.left = new FormAttachment(0, 370);
		formDataCmbSubType.width = 114;
		comboSubType.setLayoutData(formDataCmbSubType);
	}

	/**
	 * This method initializes comboCrDr
	 * 
	 */
	private void createComboCrDr() {
		comboCrDr = new Combo(this, SWT.NONE);
		FormData formDataCmbCrDr = new FormData();
		formDataCmbCrDr.top = new FormAttachment(0, 110);
		formDataCmbCrDr.left = new FormAttachment(0, 105);
		formDataCmbCrDr.width = 114;
		comboCrDr.setLayoutData(formDataCmbCrDr);
	}

	/**
	 * This method initializes comboNegativeBal
	 * 
	 */
	private void createComboNegativeBal() {
		comboNegativeBal = new Combo(this, SWT.NONE);
		FormData formDataCmbNegativeBal = new FormData();
		formDataCmbNegativeBal.top = new FormAttachment(0, 110);
		formDataCmbNegativeBal.left = new FormAttachment(0, 370);
		formDataCmbNegativeBal.width = 114;
		comboNegativeBal.setLayoutData(formDataCmbNegativeBal);
	}

	private void setParentData(SubjectDto subjectDto) {

		String parentCode = "";
		String parentSubName = "";
		String parentSublevel = "0";
		if (subjectDto != null) {
			parentCode = String.valueOf(subjectDto.getSubCode());
			parentSubName = subjectDto.getSubName();
			parentSublevel = subjectDto.getSubLevel();
			int sl = Integer.parseInt(parentSublevel);
			parentSublevel = String.valueOf(sl + 1);
		}
		textParentCode.setText(parentCode);
		textParent.setText(parentSubName);
		textSubLevel.setText(parentSublevel);
	}

	private void loadData(SubjectDto subjectDto) {
		// TODO Auto-generated method stub
		// loadSubType
		// loadCrDr
		// loadNegativeBal
	}
}
